<template>
  <div class="panel">
    <div class="toolbar">
      <el-input v-model="q.keyword" placeholder="搜索工单号/内容" clearable style="max-width:260px" @keyup.enter.native="getList"/>
      <el-button type="primary" @click="getList">查询</el-button>
    </div>

    <el-table :data="rows" border stripe height="440" v-loading="loading">
      <el-table-column prop="orderNo" label="工单号" width="160" />
      <el-table-column prop="orderDate" label="工单日期" width="160" />
      <el-table-column prop="content" label="工单内容" />
      <el-table-column prop="operation" label="作业内容" />
      <el-table-column prop="involveFix" label="维修涉及" width="100">
        <template #default="{row}">
          <el-tag size="small" :type="row.involveFix ? 'danger' : 'info'">{{ row.involveFix ? '涉及' : '—' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="afterTuning" label="完成后调试数据" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="q.pageNum"
      v-model:limit="q.pageSize"
      @pagination="getList"
    />
    <el-empty v-if="!loading && rows.length===0" description="暂无工单"/>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { listAssetWorkOrders } from '@/api/sbtz/assetExtra'

const props = defineProps({ node: Object })
const loading = ref(false)
const rows = ref([])
const total = ref(0)
const q = ref({ pageNum: 1, pageSize: 10, keyword: '' })

async function getList() {
  if (!props.node?.id) return
  loading.value = true
  try {
    const { rows: list = [], total: t = 0 } = await listAssetWorkOrders({
      assetId: props.node.id,
      pageNum: q.value.pageNum,
      pageSize: q.value.pageSize,
      keyword: q.value.keyword || null
    })
    rows.value = list
    total.value = Number(t) || 0
  } finally {
    loading.value = false
  }
}
watch(()=>[props.node?.id, q.value.pageNum, q.value.pageSize], getList, { immediate:true })
</script>

<style scoped>
.panel{ padding:8px; }
.toolbar{ display:flex; gap:8px; margin-bottom:8px; }
</style>
